#!/bin/sh

while read file
do
		case "$1" in
		# Copy the image name
		"C-c")
					echo -n "$file" | xclip -selection clipboard ;;
		# Delete images
		"C-d")
					rm "$file"  ;;
		# Set wallpaper
		"C-w")
					hsetroot -fill "$file" ;;
		# Upload image on fiery
		"C-u")
				finalResult="$(curl -sf -F files[]="@$file" https://safe.fiery.me/api/upload)"
				finalResult="$(echo "${finalResult}" | grep -Po '"url":"[A-Za-z0-9]+.*?"' | sed 's/"url":"//;s/"//')"
				printf "$finalResult" | xclip -selection clipboard
				notify-send "Uploaded!" "${finalResult}"
			;;
		esac
done
